package com.beardedcoder.lowPower.dao;

import com.beardedcoder.lowPower.app.AppSettings;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public final class DbLowPower extends SQLiteOpenHelper
{
	private static final String DATABASE = "lowpowerdb.db";
	private static final int DATABASE_VERSION = 1;
	private static final String CREATE_TABLE_BATTERY_INFO =
		"CREATE TABLE batteryinfo (id INTEGER PRIMARY KEY AUTOINCREMENT, " +
		"datetime DATETIME NOT NULL, " +
		"powerlevel INT NOT NULL, " +
		"voltage INT NULL, " +
		"health INT NOT NULL, " +
		"status VARCHAR NOT NULL, " +
		"tech VARCHAR NULL, " +
		"temperature REAL NULL, " +
		"source VARCHAR NOT NULL); " +
		"CREATE TABLE dbversion (id INTEGER PRIMARY KEY, lastupdated DATETIME NOT NULL); ";
	
	/**
	 * {@inheritDoc}
	 */
	public DbLowPower(Context context)
	{
		super(context, DATABASE, null, DATABASE_VERSION);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void onCreate(SQLiteDatabase database)
	{
		database.execSQL(CREATE_TABLE_BATTERY_INFO);		
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
		// TODO Actually do something about upgrading the database
		AppSettings.log(this.getClass(), "onUpgrade", "TODO Actually do something about upgrading the database");
	}
}
